﻿using aier.dataaccess.model;
using Dapper;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aier.dataaccess.dapper
{
    public class ScreenTSCItemDal
    {
        public ILog log { get; set; }
        public DapperHelper dapperHelper { get; set; }

        /// <summary>
        /// 获取所有筛查检查项目
        /// 原程序 ：ScItemServiceImpl-> Map<String, AierTScItem> getAll()
        /// </summary>
        /// <returns></returns>
        public IEnumerable<T_SC_ItemView> GetScreenAllSCItem()
        {
            return dapperHelper.ExecueWithoutTransaction<IEnumerable<T_SC_ItemView>>(a =>
            {
                string sql = @"select * from AIER_T_SC_ITEM ";
                SqlBuilder sqlBuilder = new SqlBuilder();
                var sqlTemplate = sqlBuilder.AddTemplate(sql);
                return a.Query<T_SC_ItemView>(sqlTemplate.RawSql);
            });
        }

        /// <summary>
        /// 根据ItemId获取筛查检查项目
        /// 原程序 ：ScItemServiceImpl-> AierTScItem getById(String itemid)
        /// </summary>
        /// <returns></returns>
        public T_SC_ItemView  GetScreenSCItemByItemId(string itemId)
        {
            return dapperHelper.ExecueWithoutTransaction<T_SC_ItemView>(a =>
            {
                string sql = $@"select * from AIER_T_SC_ITEM where new_itemid='{itemId}'";
                SqlBuilder sqlBuilder = new SqlBuilder();
                var sqlTemplate = sqlBuilder.AddTemplate(sql);
                return a.QueryFirstOrDefault<T_SC_ItemView>(sqlTemplate.RawSql);
            });
        }


    }
}
